import { apiArea } from 'js/api'
import { storage } from 'js/util'

export default {
  state: {
    areaList: ([] || storage.get('areaList')),
    isLoading: false
  },
  getters: {
    areaList: state => state.areaList,
    isLoading: state => state.isLoading
  },
  actions: {
    /**
     * 获取所有区域
     */
    fetchAllArea({ state }, callback) {
      if (!state.areaList.length) {
        apiArea().then(data => {
          state.areaList = data.data
          storage.set('areaList', state.areaList)
          state.isLoading = true
          callback && callback()
        })
      } else {
        state.isLoading = true
        callback && callback()
      }
    }
  }
}